package com.example.jwt.util;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult success() {
        return ResponseResult.success(HttpStatus.OK.value(), "操作成功", null);
    }

    public static ResponseResult success(String msg) {
        return ResponseResult.success(HttpStatus.OK.value(), msg, null);
    }

    public static ResponseResult success(Integer code, String msg, Object data) {
        return new ResponseResult(code, msg, data);
    }

    public static ResponseResult error() {
        return ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "操作失败", null);
    }

    public static ResponseResult error(String msg) {
        return ResponseResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, null);
    }

    public static ResponseResult error(Integer code, String msg, Object data) {
        return new ResponseResult(code, msg, data);
    }
}
